/*
* jlb
*/
package com.jlb.star.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.star.entity.StarLevelRule;
import com.jlb.star.service.StarLevelRuleSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 规则 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/starLevelRule")
@Slf4j
@Api(value = "规则控制器", description = "规则控制器")
public class StarLevelRuleCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private StarLevelRuleSV starLevelRuleSV;

    /**
     * 查询StarLevelRule一个详情信息
     *
     * @param id
     * @param starLevelCode 星级编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevelRule一个详情信息", notes = "查询StarLevelRule一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String starLevelCode) {
        if (id == null) {
            return null;
        }
        if (starLevelCode == null) {
            return null;
        }
        StarLevelRule starLevelRule = starLevelRuleSV.load(id, starLevelCode);
        log.info(JSON.toJSONString(starLevelRule));
        return BeanRet.create(true, "查询成功", starLevelRule);
    }


    /**
     * 根据条件id查询StarLevelRule一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevelRule一个详情信息", notes = "查询StarLevelRule一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        StarLevelRule starLevelRule = starLevelRuleSV.loadById(id);
        log.info(JSON.toJSONString(starLevelRule));
        return BeanRet.create(true, "查询成功", starLevelRule);
    }

    /**
     * 根据条件starLevelCode查询StarLevelRule一个详情信息
     *
     * @param starLevelCode 星级编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询StarLevelRule一个详情信息", notes = "查询StarLevelRule一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/starLevelCode/{starLevelCode}")
    @ResponseBody
    public BeanRet loadByStarLevelCode(@PathVariable java.lang.String starLevelCode) {
        if (starLevelCode == null) {
            return null;
        }
        StarLevelRule starLevelRule = starLevelRuleSV.loadByStarLevelCode(starLevelCode);
        log.info(JSON.toJSONString(starLevelRule));
        return BeanRet.create(true, "查询成功", starLevelRule);
    }


    /**
     * 查询StarLevelRule信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询StarLevelRule信息集合", notes = "查询StarLevelRule信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore StarLevelRule starLevelRule, Integer curPage, Integer pageSize) {
        Page<StarLevelRule> page = new Page<StarLevelRule>(pageSize, curPage);
        List<StarLevelRule> starLevelRules = starLevelRuleSV.list(starLevelRule, page.genRowStart(), page.getPageSize());
        page.setVoList(starLevelRules);
        int total = starLevelRuleSV.count(starLevelRule);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询StarLevelRule信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询StarLevelRule信息集合", notes = "查询StarLevelRule信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String starLevelCode, Integer curPage, Integer pageSize) {
        Page<StarLevelRule> page = new Page<StarLevelRule>(pageSize, curPage);
        List<StarLevelRule> starLevelRules = starLevelRuleSV.list(id, starLevelCode, page.genRowStart(), page.getPageSize());
        page.setVoList(starLevelRules);
        int total = starLevelRuleSV.count(id, starLevelCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计StarLevelRule信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计StarLevelRule信息数量根据主键", notes = " 统计StarLevelRule信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String starLevelCode) {
        return starLevelRuleSV.count(id, starLevelCode);
    }

    /**
     * 统计StarLevelRule信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计StarLevelRule信息数量", notes = "统计StarLevelRule信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", paramType = "query"),
            @ApiImplicitParam(name = "level", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态奖励百分比", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore StarLevelRule starLevelRule) {
        if (starLevelRule == null) {
            return starLevelRuleSV.count(new HashMap());
        } else {
            return starLevelRuleSV.count(starLevelRule);
        }
    }


    /**
     * 创建StarLevelRule
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建StarLevelRule", notes = "创建StarLevelRule")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "level", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态奖励百分比", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore StarLevelRule starLevelRule) {
        starLevelRuleSV.save(starLevelRule);
        return BeanRet.create(true, "创建成功", starLevelRule);
    }


    /**
     * 修改StarLevelRule
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改StarLevelRule", notes = "修改StarLevelRule")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", paramType = "query"),
            @ApiImplicitParam(name = "level", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态奖励百分比", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore StarLevelRule starLevelRule) {
        starLevelRuleSV.modify(starLevelRule);
        return BeanRet.create(true, "修改成功", starLevelRule);
    }

    /**
     * 删除StarLevelRule
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除StarLevelRule", notes = "删除StarLevelRule")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "starLevelCode", value = "星级编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String starLevelCode) {
        starLevelRuleSV.delete(id, starLevelCode);
        return BeanRet.create(true, "删除StarLevelRule成功");
    }

}
